﻿using System;
using System.Data;
using DotNetNuke.Entities.Content;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;

namespace DotNetNuke.Modules._2DoTasks.Components.Entities
{
    public class _TaskComment : ContentItem
    {
        public int Id { get; set; }

        public int TaskId { get; set; }

        public string Comment { get; set; }

        public int CreationUserId { get; set; }

        public DateTime CreationDate { get; set; }

        public int LastChangeUserId { get; set; }

        public DateTime LastChangeDate { get; set; }

        /// <summary>
        /// The creation user display name
        /// </summary>
        public UserInfo CreatedByUser
        {
            get
            {
                return CreationUserId != 0 ? UserController.GetUserById(PortalController.GetCurrentPortalSettings().PortalId, CreationUserId) : null;
            }
        }

        /// <summary>
        /// the last change user display name
        /// </summary>
        public UserInfo LastChangeUser
        {
            get
            {
                return LastChangeUserId != 0 ? UserController.GetUserById(PortalController.GetCurrentPortalSettings().PortalId, LastChangeUserId) : null;
            }
        }

        #region IHydratable Implementation

        public override void Fill(IDataReader dr)
        {
            Id = Convert.ToInt32(dr["TskCm_Id"]);

            TaskId = Convert.ToInt32(dr["TskCm_TaskId"]);

            Comment = dr["TskCm_Comment"].ToString();

            CreationUserId = Convert.ToInt32(dr["TskCm_CreationUserId"]);

            CreationDate = Convert.ToDateTime(dr["TskCm_CreationDate"]);

            LastChangeUserId = Convert.ToInt32(dr["TskCm_LastChangeUserId"]);

            LastChangeDate = Convert.ToDateTime(dr["TskCm_LastChangeDate"]);

            //base.FillInternal(dr);  ToDo - Implement Taxonomy
        }

        public override int KeyID
        {
            get
            {
                return Id;
            }
            set
            {
                Id = value;
            }
        }

        #endregion IHydratable Implementation
    }
}